
package com.bh.framework.common;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;

import com.bh.ly.oa.R;

public class LoadingDialog
{
	private Dialog pd;
	private Activity mActivity;
	private TextView loadingText;

	public LoadingDialog(Activity context, String message)
	{
		mActivity = context;
		pd = new Dialog(context, R.style.dialog);
		View view = LayoutInflater.from(context).inflate(
				R.layout.layout_loading, null);
		view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT));
		loadingText = (TextView) view.findViewById(R.id.loading_text);
		if (message != null)
		{
			loadingText.setText(message);
		}
		pd.setContentView(view);
	}

	public LoadingDialog setLoadingText(String text)
	{
		loadingText.setText(text);
		return this;
	}

	public void show()
	{
		if (!mActivity.isFinishing() && !pd.isShowing())
		{
			pd.show();
		}
	}

	public void close()
	{
		if (!mActivity.isFinishing() && pd.isShowing())
		{
			pd.dismiss();
		}
	}

	public boolean isShow()
	{
		return pd.isShowing();
	}

	public void setOnCancelListener(DialogInterface.OnCancelListener l)
	{
		pd.setOnCancelListener(l);
	}

}
